package me.mytest;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        ArrayList<PersianCat> list1 = new ArrayList<>();
        ArrayList<LiHuaCat> list2 = new ArrayList<>();
        ArrayList<HuskyDog> list3 = new ArrayList<>();
        ArrayList<TeddyDog> list4 = new ArrayList<>();

        list1.add(new PersianCat());
        list1.get(0).setName("咪咪");
        list1.get(0).setAge(3);

        /*分开写的方式，更清晰但代码
        PersianCat cat = new PersianCat();
        cat.setName("咪咪");
        cat.setAge(3);
        list1.add(cat); */

        list2.add(new LiHuaCat());
        list2.get(0).setName("大黄");
        list2.get(0).setAge(2);

        list3.add(new HuskyDog());
        list3.get(0).setName("阿哈");
        list3.get(0).setAge(1);

        list4.add(new TeddyDog());
        list4.get(0).setName("豆豆");
        list4.get(0).setAge(4);

        list4.add(new TeddyDog());
        list4.get(1).setName("困困");
        list4.get(1).setAge(2);

        //另一种写法
  /*      TeddyDog dog1 = new TeddyDog();
        dog1.setName("豆豆");
        dog1.setAge(4);
        list4.add(dog1);

        TeddyDog dog2 = new TeddyDog();
        dog2.setName("困困");
        dog2.setAge(2);
        list4.add(dog2);*/

        // 添加到集合
        keepPet(list1);
        keepPet(list2);
        keepPet(list3);
        keepPet(list4);
    }

    //该方法能养所有的动物，不能传递其他类型
    //增强for循环
    public static void keepPet(ArrayList<? extends Animal> list) {
        for (Animal animal : list) {
            System.out.println("养了一只: " + animal);
            animal.eat();
        }

        System.out.println("------------------------");
    }
}
